 #ifndef SESSIONFRIENDAREA_H
#define SESSIONFRIENDAREA_H

#include <QWidget>
#include <QScrollArea>
#include <QLabel>


/*
 *
 * 滚动区Item类型
 */
enum ItemType{
    SessionItemType,
    FriendItemType,
    ApplyItemType
};



/*
 * 滚动区实现
 *
 */
class SessionFriendArea : public QScrollArea
{
    Q_OBJECT
public:
    explicit SessionFriendArea(QWidget *parent = nullptr);

    void clear();
    void addIem(ItemType itemType, const QString& id, const QIcon& avatar, const QString& name, const QString& text, const QString& time = "");
    void clickItem(int index);


private:
    // 滚动效果
    QWidget* container;

signals:
};



/*
 * 滚动区Item实现
 *
 */
class SessionFriendItem : public QWidget{
    Q_OBJECT

public:
    SessionFriendItem(QWidget* owner, const QIcon& avatar, const QString& name, const QString& text, const QString& time = "");

    void paintEvent(QPaintEvent* event) override;
    void mousePressEvent(QMouseEvent* event) override;
    void enterEvent(QEnterEvent* event) override;
    void leaveEvent(QEvent* event) override;

    void select();
    virtual void active();  // 处理被点击的业务逻辑

protected:
    QLabel* timeLabel;
    QLabel* messageLabel;

private:
    QWidget* owner;

    bool selected = false;  // 是否被选中
};


/*
 *
 * 会话Item实现
 */
class SessionItem : public SessionFriendItem{
    Q_OBJECT
public:
    SessionItem(QWidget* owner, const QString& chatSessionId, const QIcon& avatar, const QString& name, const QString& lastMessage, const QString& time = "");

    void active() override;

    void updateLastMessage(const QString& chatSessionId);
private:
    QString chatSessionId;  // 会话id
    // 最后一条消息的文本预览
    QString text;
    QString time;
};


/*
 *
 * 好友Item实现
 */
class FriendItem : public SessionFriendItem{
    Q_OBJECT
public:
    FriendItem(QWidget* owner, const QString& userId, const QIcon& avatar, const QString& name, const QString& description);

    void active() override;
private:
    QString userId;
};


/*
 *
 * 好友申请Item实现
 */
class ApplyItem : public SessionFriendItem{
    Q_OBJECT
public:
    ApplyItem(QWidget* owner, const QString& userId, const QIcon& avatar, const QString& name);

    void active() override;

    void acceptFriendApply();
    void rejectFriendApply();
private:
    QString userId;
};




#endif // SESSIONFRIENDAREA_H








